home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1642 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: io.UWinnipeg.ca!wsimpson
  2. From: Bill Simpson <wsimpson@uwinnipeg.ca>
  3. Newsgroups: comp.lang.c
  4. Subject: swap high and low 16 bits?
  5. Date: Mon, 15 Jan 1996 17:55:15 -0600
  6. Organization: The University of Manitoba
  7. Message-ID: <Pine.OSF.3.91.960115174921.19742A-100000@io.UWinnipeg.ca>
  8. NNTP-Posting-Host: io.uwinnipeg.ca
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; charset=US-ASCII
  11.  
  12. I wanted to obtain a "random" starting number each time a program
  13. is run.  The obvious choice is time(NULL).  The problem with it is that
  14. if the program runs and terminates fairly quickly, the number returned by 
  15. time(NULL) is quite similar each run, differing only by the lowest bits.
  16.  
  17. One solution would be to swap the high 16 bits and the low 16 bits of the
  18. 32 bit unsigned long int.  Sorry this is dirty, not ANSI.
  19.  
  20. Could anyone please tell me how to do this?  The simpler the code the
  21. better (ANSI not important for this particular case).
  22.  
  23. Other solutions to the general problem (e.g. rotating the low bits to
  24. the high end) are welcome.
  25.  
  26. Thanks very much for any help.
  27.  
  28. Bill Simpson
  29.